#include <stdio.h>
#include <string.h>

struct man{
	char name[32];
	int year;
	int month;
	int day;
};

int main()
{
	int N = 0, num = 0;
	char name[32] = {0};
	int year = 0, month = 0, day = 0;
	scanf("%d", &N);
	
	struct man old = {"", 2014,9,6};
	struct man young = {"",0,0,0};
	struct man thisMan = {"", 0, 0, 0};
	for(int i = 0; i < N; i++){
		scanf("%s %d/%02d/%02d", &name, &year, &month, &day);
		memset(&thisMan, 0, sizeof(thisMan));
		strcpy(thisMan.name, name);
		thisMan.year = year;
		thisMan.month = month;
		thisMan.day  = day;

		if((year > 2014 || (year == 2014 && (month > 9 || (month == 9 && day > 6)))) ||
		  (year < 1814 || (year == 1814 && (month < 9 || (month == 9 && day < 6))))){
			continue;
		}
		num++;
		
		if(thisMan.year > young.year || (thisMan.year == young.year && \
		  ((thisMan.month > young.month) || (thisMan.month == young.month && thisMan.day > young.day)))){
			memset(&young, 0, sizeof(young));
			young = thisMan;
			continue;
		}
		if(thisMan.year < old.year || (thisMan.year == old.year && \
		  ((thisMan.month < old.month) || (thisMan.month == old.month && thisMan.day < old.day)))){
			memset(&old, 0, sizeof(old));
			old = thisMan;
			continue;
		  }
	}

	printf("%d %s %s\n", num, old.name, young.name);
	return 0;
}
